/**
 * one block size
 */
export const BLOCK = 16

/**
 * ms of one frame
 * based on a frame rate of 60
 */
export const F = 1000 / 60

/**
 * one grid size
 */
export const GRID = BLOCK / 2

/**
 * one char size
 */
export const CHAR = GRID

/**
 * battle area size
 * 26 grids in battle area
 */
export const FIELD = 26 * GRID

/**
 * screen size
 * includes battle area and battle show
 */
export const SCREEN = {
  width: 512,
  height: 480
}

/**
 * options in selectPlayer page
 */
export const SELECTION = {
  star: 'star on me',
  single: '1 player',
  double: '2 players',
  operate: 'custom operation',
  custom: 'custom a map',
  choose: 'choose a stage',
  mobile: 'with mobile', // default key-mouse
  rank: 'game rank',
}

/**
 * terrain type & size in one unit
 */
export const TERRAIN = {
  size: GRID,
  list: ['brick', 'steel', 'forest', 'river', 'snow'], // type -> 1, 2, 3, 4, 5
}

/**
 * bullet
 */
export const BULLET = {
  size: 3,
  gap: BLOCK, // distance between two bullets
  level: [
    { power: 1, count: 1, brick: 1, steel: 0, max: 1, speed: 2 },
    { power: 1, count: 1, brick: 1, steel: 0, max: 1, speed: 3 },
    { power: 1, count: 1, brick: 1, steel: 0, max: 2, speed: 3 },
    { power: 3, count: 1, brick: 2, steel: 1, max: 1, speed: 4 },
    { power: 3, count: 1, brick: 2, steel: 1, max: 2, speed: 4 },
  ]
}

/**
 * speed of tank
 * unit of one frame
 */
export const SPEED = {
  slow: 0.03,
  middle: 0.045,
  fast: 0.06
}

/**
 * tanks
 */
export const TANK = {
  size: BLOCK,
  interval: 80, // interval of tank wheel animation, ms
  direction: 'down',
  colors: {
    yellow: {
      a: '#E7E794',
      b: '#E79C21',
      c: '#6B6B00',
    },
    green: {
      a: '#B5F7CE',
      b: '#008C31',
      c: '#005200',
    },
    silver: {
      a: '#FFFFFF',
      b: '#ADADAD',
      c: '#00424A',
    },
    red: {
      a: '#FFFFFF',
      b: '#B53121',
      c: '#5A007B',
    },
  },
  basic: {
    hp: 1,
    power: BULLET.level[0],
    speed: SPEED.slow, // speed of player tank is middle
    shape: [1, 2],
    score: 100,
  },
  fast: {
    hp: 2,
    power: BULLET.level[1],
    speed: SPEED.fast,
    shape: [3, 4],
    score: 200,
  },
  power: {
    hp: 2,
    power: BULLET.level[2],
    speed: SPEED.middle,
    shape: [5, 6],
    score: 300,
  },
  armor: {
    hp: 2,
    power: BULLET.level[1],
    speed: SPEED.middle,
    shape: [7, 8],
    score: 400,
  },
  // born position
  position: {
    // enemy
    left: { x: 0, y: 0 },
    center: { x: 12 * GRID, y: 0 },
    right: { x: 24 * GRID, y: 0 },
    // player
    player1: { x: 8 * GRID, y: 24 * GRID },
    player2: { x: 16 * GRID, y: 24 * GRID },
  }
}

/**
 * prop
 */
export const PROP = {
  size: BLOCK,
  score: 500,
  dur: 630 * F, // prop will disappear after dur which includes it's flicker time
  tipDur: 48 * F,
  flicker: { // flicker before prop disapear
    interval: 8 * F, // appear: 8 * F, then interval: 8 * F, switch this status total 6 times
    count: 6
  },
  tank: {
    tip: 'life +1',
    icon: [
      ' wwwwwwwwwwwwwg ',
      'w             wb',
      'w bbbbbbbbbbbbwb',
      'w bbbbbwgg bbbwb',
      'w bwwwwgggb bbwb',
      'w b    gggb bbwb',
      'w bbbwggbbgb bwb',
      'w bbwgggggbb bwb',
      'w bgbg      g wb',
      'w bggwwwwgggb wb',
      'w b w w w wbg wb',
      'w bb ggggggg bwb',
      'w bbb       bbwb',
      'gwwwwwwwwwwwwwwg',
      ' bbbbbbbbbbbbbb ',
      '                ',
    ],
  },
  star: {
    tip: 'power +1',
    icon: [
      ' wwwwwwwwwwwwwg ',
      'w             wb',
      'w bbbbbw bbbbbwb',
      'w bbbbwwg bbbbwb',
      'w bbbbwwg bbbbwb',
      'w wwwwwggwwww wb',
      'w bgggwgwggg  wb',
      'w bbgwwwwgg  wwb',
      'w bbwwggwwg bbwb',
      'w bgwgg ggwg bwb',
      'w bwgg   ggw bwb',
      'w bg   bb  g bwb',
      'w b  bbbbbb  bwb',
      'gwwwwwwwwwwwwwgb',
      ' bbbbbbbbbbbbbb ',
      '                ',
    ],
  },
  grenade: {
    tip: 'enemy boom!',
    icon: [
      ' wwwwwwwwwwwwwg ',
      'w             wb',
      'w bbbwwwgg bbbwb',
      'w bbbwgb  g bbwb',
      'w bbwgggb  g bwb',
      'w bwgbwgbg g bwb',
      'w bg g  g  g bwb',
      'w bwgbwgbg g bwb',
      'w bg g  g  g bwb',
      'w bwgbwgbg g bwb',
      'w bbgb  g bbbbwb',
      'w bbbwgg bbbbbwb',
      'w bbb   bbbbbbwb',
      'gwwwwwwwwwwwwwgb',
      ' bbbbbbbbbbbbbb ',
      '                ',
    ],
  },
  watch: {
    tip: 'enemy pause',
    icon: [
      ' wwwwwwwwwwwwwg ',
      'w             wb',
      'w bbbbwgwg bbbwb',
      'w bbbbg   wg bwb',
      'w bbbgggg    bwb',
      'w bbgwwwwg bbbwb',
      'w bgwwbwwwg bbwb',
      'w bgwwbwwwg bbwb',
      'w bgwwwbwwg bbwb',
      'w b gwwwwg bbbwb',
      'w bb gggg bbbbwb',
      'w bbb    bbbbbwb',
      'w bbbbbbbbbbbbwb',
      'gwwwwwwwwwwwwwgb',
      ' bbbbbbbbbbbbbb ',
      '                ',
    ],
    effectDur: 300 * F,
  },
  helmet: {
    tip: 'invincible timing!',
    icon: [
      ' wwwwwwwwwwwwwg ',
      'w             wb',
      'w bbbbbbbbbbbbwb',
      'w bbbbbbbbbbbbwb',
      'w bbbwwwgg bbbwb',
      'w bbwwggggg bbwb',
      'w bbwgggggg bbwb',
      'w bbggggggg bbwb',
      'w bgggggggg bbwb',
      'w b     gggg bwb',
      'w bbbbbb     bwb',
      'w bbbbbbbbbbbbwb',
      'w bbbbbbbbbbbbwb',
      'gwwwwwwwwwwwwwgb',
      ' bbbbbbbbbbbbbb ',
      '                ',
    ],
    // it's effect relates PROTECTION in this page.
  },
  shovel: {
    tip: 'steel base!',
    icon: [
      ' wwwwwwwwwwwwwg ',
      'w             wb',
      'w bbbbbbbbwbbbwb',
      'w bbbbbbbbwgbbwb',
      'w bbbbbbbbgggbwb',
      'w bbbbbbbw   bwb',
      'w bbbwbbw bbbbwb',
      'w bbwwgw bbbbbwb',
      'w bwwgbw bbbbbwb',
      'w bwgbggg bbbbwb',
      'w bggggg bbbbbwb',
      'w bgggg bbbbbbwb',
      'w b    bbbbbbbwb',
      'gwwwwwwwwwwwwwgb',
      ' bbbbbbbbbbbbbb ',
      '                ',
    ],
    effect: {
      dur: 1268 * F, // total duration of effect
      flicker: {
        interval: 16 * F, // brick: 16 * F, then interval: 16 * F, switch this status total 5 times, finally to brick
        count: 5
      }
    }
  },
  pistol: {
    tip: 'power +3',
    icon: [
      ' wwwwwwwwwwwwwg ',
      'w             wb',
      'w bbbbbbbbwbbbwb',
      'w bwbbbbbbbbbbwb',
      'w gwwwwwwwg bbwb',
      'w wggggggggg bwb',
      'w  ggbbbbbbg bwb',
      'w b  ggwggggg wb',
      'w bbb g  gwbg wb',
      'w bbbb gggwbg wb',
      'w bbbbb  gbbg wb',
      'w bbbbbbbgggg wb',
      'w bbbbbbb    bwb',
      'gwwwwwwwwwwwwwgb',
      ' bbbbbbbbbbbbbb ',
      '                '
    ],
  },
}

/**
 * players config
 */
export const PLAYERS = {
  hp: 3,
  player1: {
    color: 'yellow',
    x: TANK.position.player1.x,
    y: TANK.position.player1.y,
  },
  player2: {
    color: 'green',
    x: TANK.position.player2.x,
    y: TANK.position.player2.y,
  },
  direction: 'up',
  speed: SPEED.middle,
  power: 0, // BULLET.level[0]
  shape: 1, // 1-8
  score2HP: 10000, // add 1 hp every 10000 score
}

/**
 * flicker animation
 */
export const FLICKER = {
  size: BLOCK,
  process: [
    { type: 4, dur: 3 * F },
    { type: 3, dur: 3 * F },
    { type: 2, dur: 3 * F },
    { type: 1, dur: 3 * F },
    { type: 2, dur: 3 * F },
    { type: 3, dur: 3 * F },
    { type: 4, dur: 3 * F },
    { type: 3, dur: 3 * F },
    { type: 2, dur: 3 * F },
    { type: 1, dur: 3 * F },
    { type: 2, dur: 3 * F },
    { type: 3, dur: 3 * F },
    { type: 4, dur: 1 * F },
  ],
}

/**
 * explosion for bullet & tank
 */
export const EXPLOSION = {
  bullet: {
    size: BLOCK,
    process: [
      { type: 's0', dur: 4 * F },
      { type: 's1', dur: 3 * F },
      { type: 's2', dur: 2 * F },
    ]
  },
  tank: {
    size: 2 * BLOCK,
    process: [
      { type: 's0', dur: 7 * F },
      { type: 's1', dur: 5 * F },
      { type: 's2', dur: 7 * F },
      { type: 'b0', dur: 5 * F },
      { type: 'b1', dur: 7 * F },
      { type: 's2', dur: 5 * F }
    ]
  }
}

/**
 * protection of helmet & players born
 */
export const PROTECTION = {
  size: BLOCK,
  interval: 2 * F,
  dur: {
    born: 135 * F, // receive protection by born
    helmet: 180 * F // receive protection by helmet prop
  }
}

/**
 * pause interval
 */
export const PAUSE = {
  interval: 15 * F
}

/**
 * eagle base
 */
export const EAGLE = {
  size: BLOCK,
  x: 12 * GRID,
  y: 24 * GRID
}

/**
 * enemy config
 */
export const ENEMY = {
  maxAlive: 4,
  maxCountInOneStage: 20,
  minRedCount: 3,
  maxRedCount: 8,
  explosionScore: 100
}

/**
 * keys controller
 */
export const CONTROLLER = {
  player1: {
    up: 'w',
    down: 's',
    left: 'a',
    right: 'd',
    shoot: 'j',
    borrow: 'b', // borrow a hp from player2
    'w': 'up',
    's': 'down',
    'a': 'left',
    'd': 'right',
    'j': 'shoot',
    'b': 'borrow',
  },
  player2: {
    up: 'ArrowUp',
    down: 'ArrowDown',
    left: 'ArrowLeft',
    right: 'ArrowRight',
    shoot: ' ', // Space key
    borrow: 'y',
    'ArrowUp': 'up',
    'ArrowDown': 'down',
    'ArrowLeft': 'left',
    'ArrowRight': 'right',
    ' ': 'shoot',
    'y': 'borrow',
  },
}